<?php
namespace app\index\controller;

use app\common\model\PlanModel;
use think\facade\Env;

class Effect extends Base
{
	/**
	 * 按人员统计
	 * @Author   zhibin3
	 * @DateTime 2022-10-20
	 * @return   [type]     [description]
	 */
	public function index()
	{
		MkEncrypt('000000'); //页面加密访问
		
		$re = request();
        if (!$re->isAjax()) {
        	$person_list = [
        		1 => '张三',
        		2 => '李四',
        		3 => '王五',
        	];

			$this->assign([
				'person_list' => $person_list,
			]);
			
			return $this->fetch('index');
        }

		$person_id = input('get.person_id', 0, 'intval');
		$page = input('get.page', 1, 'intval');
		$limit = input('get.limit', 15, 'intval');

		$where = [
			['pp.person_id', '=', $person_id],
			['pr.id', '>', 0],
		];
		$field = 'pr.id,pr.title,pr.product_code,sum(o.deal_price) amount,sum(o.product_count) product_count,pr.cost';
		$PlanModel = new PlanModel();
		$pageList = $PlanModel->getStaticsByPerson($where, $page, $limit, $field);
		if ($pageList['total'] > 0) {
			foreach ($pageList['data'] as $key => &$value) {
				$value['cost_amount'] = bcmul($value['product_count'], $value['cost'], 2);
			}
		}

		return json([
            'code' => 0,
            'msg' => 'Success',
            'count' => $pageList['total'], 
            'data' => $pageList['data'],
        ]);
	}


}